using SmartLink.Application.IServices;
using SmartLink.DTOS;
using SmartLink.DTOS.SysBasic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace SmartLink.WebApi.Controllers.System
{
    /// <summary>
    /// 系统功能模块
    /// </summary>
    public class SysModuleController : BaseAPIControl
    {
        private ISysModuleAppServices _sysModuleAppServices;

        public SysModuleController(ISysModuleAppServices sysModuleAppServices)
        {
            _sysModuleAppServices = sysModuleAppServices;
        }

        #region 系统模块

        /// <summary>
        /// 添加模块
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public Results AddModule(SysModuleDTO model)
        {
            return _sysModuleAppServices.AddModule(model);
        }
        /// <summary>
        /// 更新模块
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public Results UpdateModule(SysModuleDTO model)
        {
            return _sysModuleAppServices.UpdateModule(model);
        }
        /// <summary>
        /// 删除模块
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public Results DeleteModule(int id)
        {
            return _sysModuleAppServices.DeleteModule(id);
        }
        /// <summary>
        /// 获取模块详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public Results<SysModuleDTO> GetModule(int id)
        {
            return _sysModuleAppServices.GetModule(id);
        }
        /// <summary>
        /// 获取模块直系子模块
        /// </summary>
        /// <param name="parantId"></param>
        /// <returns></returns>
        [HttpPost]
        public Results<IEnumerable<SysModuleDTO>> GetModuleChildren(int parantId)
        {
            return _sysModuleAppServices.GetModuleChildren(parantId);
        }
        /// <summary>
        /// 获取模块树结构
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public Results<IList<SysModuleTreeNodeDTO>> GetModuleTree()
        {
            return _sysModuleAppServices.GetModuleTree();
        }

        #endregion

        #region 模块功能项

        /// <summary>
        /// 添加模块功能
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public Results AddFunction(SysModuleFunctionDTO model)
        {
            return _sysModuleAppServices.AddFunction(model);
        }
        /// <summary>
        /// 更新模块功能
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        [HttpPost]
        public Results UpdateFunction(SysModuleFunctionDTO model)
        {
            return _sysModuleAppServices.UpdateFunction(model);
        }
        /// <summary>
        /// 删除模块功能
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public Results DeleteFunction(int id)
        {
            return _sysModuleAppServices.DeleteFunction(id);
        }
        /// <summary>
        /// 获取模块功能详情
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpPost]
        public Results<SysModuleFunctionDTO> GetFunction(int id)
        {
            return _sysModuleAppServices.GetFunction(id);
        }
        /// <summary>
        /// 获取模块功能列表
        /// </summary>
        /// <param name="moduleCode"></param>
        /// <returns></returns>
        [HttpPost]
        public Results<IEnumerable<SysModuleFunctionDTO>> GetModuleFunctions(string moduleCode)
        {
            return _sysModuleAppServices.GetModuleFunctions(moduleCode);
        }

        #endregion

        /// <summary>
        /// 获取模块列表，带模块功能
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public Results<IList<SysModuleWithFunctionsListItemDTO>> GetModuleAndFunctionsList()
        {
            return _sysModuleAppServices.GetModuleAndFunctionsList();
        }
    }
}
